package com.chapter13.MyCollection.MyList.Listcompare;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class TestList {
    public static <E> void testSuite(List<Integer> list){
        long addTime,getTime,setTime,removeTime;

        //匿名内部类
        //在索引为0的位置添加1000个元素
        addTime= Tester.runTest(new Test() {
            @Override
            public void test() {
                for (int i=0;i<1000;i++){
                    list.add(0,i);
                }
            }
        });


        //获取1000个元素
        getTime=Tester.runTest(new Test() {
            @Override
            public void test() {
                for (int i=0;i<1000;i++){
                    list.get(i);
                }
            }
        });



        //修改元素
        setTime=Tester.runTest(new Test() {
            @Override
            public void test() {
                for (int i=0;i<1000;i++){
                    list.set(i,888);
                }
            }
        });



        //获取1000个元素
        removeTime=Tester.runTest(new Test() {
            @Override
            public void test() {
                for (int i=0;i<1000;i++){
                    list.remove(0);
                }
            }
        });


        System.out.println(addTime+" "+ getTime+" "+setTime+" "+removeTime);
    }

    public static void main(String[] args) {
        ArrayList<Integer> arrayList = new ArrayList<Integer>();
        testSuite(arrayList);
        LinkedList<Integer> linkedList = new LinkedList<Integer>();
        testSuite(linkedList);
    }
}
